<template>
    <view>
        <form @submit.prevent="handleLogin">
            <input v-model="username" placeholder="用户名" />
            <input v-model="password" type="password" placeholder="密码" />
            <button type="submit">登录</button>
        </form>
    </view>
</template>

<script>
export default {
    data() {
        return {
            username: '',
            password: ''
        };
    },
    methods: {
        handleLogin() {
            // 模拟登录请求
            this.$u.post('/api/login', {
                username: this.username,
                password: this.password
            }).then(response => {
                if (response.success) {
                    // 登录成功，存储登录状态
                    uni.setStorageSync('isLoggedIn', true);
                    uni.setStorageSync('token', response.token); // 假设返回了一个token
                    // 跳转到首页或其他页面
                    this.$u.route({
                        url: '/pages/index/index'
                    });
                } else {
                    // 处理登录失败
                    this.$u.toast('登录失败，请检查用户名和密码');
                }
            }).catch(error => {
                console.error('登录请求失败', error);
                this.$u.toast('登录请求失败，请稍后重试');
            });
        }
    }
}
</script> 